﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace CustomProvider
{
    public class CommonMethodProvider
    {
        /// <summary>
        /// Get Player Name from IDPLayer
        /// </summary>
        /// <param name="IDPlayer"></param>
        /// <returns></returns>
        public static string GetPlayerNameFromIDPlayer(string IDPlayer)
        {
            return IDPlayer.Split(new char[] { '@' }).First();
        }

        /// <summary>
        /// Get IPAddress from IDPLayer
        /// </summary>
        /// <param name="IDPlayer"></param>
        /// <returns></returns>
        public static string GetIPAddressFromIDPlayer(string IDPlayer)
        {
            return IDPlayer.Split(new char[] { '@' }).Last();
        }

        /// <summary>
        /// Retrieve IP address of own computer
        /// </summary>
        /// <returns></returns>
        public static string RetrieveIPAddress()
        {
            IPHostEntry hostByName = Dns.GetHostByName(Dns.GetHostName());
            IPAddress address = hostByName.AddressList.First();
            return address == null ? string.Empty : address.ToString();
        }
    }
}
